<template>
  <div class="list-container">
    <el-divider>检查项维护树</el-divider>
    <map-tree
      v-if="treeData.length"
      :data.sync="treeData"
      :usual_drop="buildingDrops"
      :end_drop="houseDrops"
      :delete_node="deleteNode"
      :rename="rename"
      :add_node="addNode"
      :root_drops="rootDrops"
    ></map-tree>
  </div>
</template>
<script>
  import MapTree from '@/components/MapTree'
  import { getAllPart, addPart, deleteById, updatePart } from '@/api/tree'
  export default {
    name: 'Features',
    components: { MapTree },
    data() {
      return {
        treeData: [],
        buildingDrops: [
          {
            op: 'addCheckPoint',
            value: '添加子项',
          },
          {
            op: 'rename',
            value: '编辑',
          },
          {
            op: 'rm',
            value: '删除该节点',
          },
        ],
        houseDrops: [
          {
            op: 'rename',
            value: '编辑',
          },
          {
            op: 'rm',
            value: '删除该节点',
          },
        ],
        rootDrops: [
          {
            op: 'addCheckPoint',
            value: '添加子项',
          },
        ],
      }
    },
    computed: {},
    created() {
      // let temp = {
      //   partId:
      //     'khiltbqxywhghqnkvibwspgnxuangsawkqcgwzdvwmhaaiwvawzcpawntmgyshvi',
      //   partName: '房屋芯造',
      // }
      // this.rename(temp)
    },
    mounted() {
      this.fetchTree()
    },
    methods: {
      async deleteNode(id) {
        let push = {}
        push.partId = id
        const { data: res } = await deleteById(push)
      },
      async rename(item) {
        console.log(item)
        const { data: res } = await updatePart(item)
      },
      async fetchTree() {
        const { data: res } = await getAllPart()
        this.treeData = res.body
      },
      async addNode(node) {
        const { data: res } = await addPart(node)
      },
    },
  }
</script>
